package dom.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dom.bean.User;
import dom.dao.UserDao;

public class PageDao extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public PageDao() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	
		String action=request.getParameter("action");
		
		if(action!=null&&action.equals("CpNews")){
			//公司资讯
			request.setAttribute("mainRight", "CompanyNews.jsp");
			request.getRequestDispatcher("../Main.jsp").forward(request, response);
		}else if(action!=null&&action.equals("CompanyIntro")){
			//公司简介
			request.setAttribute("mainRight", "BriefIntro.jsp");
			request.getRequestDispatcher("../Main.jsp").forward(request, response);
		}else if(action!=null&&action.equals("ManagerDefault")){
			//首页
			request.setAttribute("mainRight", "ManagerDefault.jsp");
			request.getRequestDispatcher("../Main.jsp").forward(request, response);
		}else if(action!=null&&action.equals("StaffRe")){
			//员工招聘
			request.setAttribute("mainRight", "StaffRecruitment.jsp");
			request.getRequestDispatcher("../Main.jsp").forward(request, response);
		}else if(action!=null&&action.equals("WineCatogory")){
			//红酒分类
			request.setAttribute("mainRight", "WineCatg.jsp");
			request.getRequestDispatcher("../Main.jsp").forward(request, response);
		}else if(action!=null&&action.equals("ProductManage")){
			//产品管理
			request.setAttribute("mainRight", "ProductManage.jsp");
			request.getRequestDispatcher("../Main.jsp").forward(request, response);
		}else if(action!=null&&action.equals("WineKnologe")){
			//红酒知识
			request.setAttribute("mainRight", "WineKnologe.jsp");
			request.getRequestDispatcher("../Main.jsp").forward(request, response);
		}else if(action!=null&&action.equals("KnoUp")){
			//红酒知识修改
			request.setAttribute("mainRight", "KnoUp.jsp");
			request.getRequestDispatcher("../Main.jsp").forward(request, response);
		}else if(action!=null&&action.equals("PSW")){
			//修改密码
			request.setAttribute("mainRight", "PSW.jsp");
			request.getRequestDispatcher("../Main.jsp").forward(request, response);
		}else if(action!=null&&action.equals("Manager")){
			//修改个人信息
			String code=request.getParameter("code");
			request.setAttribute("mainRight", "InfoUpdate.jsp?code="+code);
			request.getRequestDispatcher("../Main.jsp").forward(request, response);
		}else if(action!=null&&action.equals("ProdUp")){
			//修改个人信息
			int id=Integer.parseInt(request.getParameter("id")) ;
			int catid=Integer.parseInt(request.getParameter("catid"));
			request.setAttribute("mainRight", "ProductUpdate.jsp?id="+id+"&catid="+catid);
			request.getRequestDispatcher("../Main.jsp").forward(request, response);
		}else if(action!=null&&action.equals("WineCatUp")){
			//分类修改
			int id=Integer.parseInt(request.getParameter("id")) ;
			request.setAttribute("mainRight", "WineCatUp.jsp?id="+id);
			request.getRequestDispatcher("../Main.jsp").forward(request, response);
		}else if(action!=null&&action.equals("NewsUp")){
			//新闻修改
			int id=Integer.parseInt(request.getParameter("id")) ;
			request.setAttribute("mainRight", "NewsUp.jsp?id="+id);
			request.getRequestDispatcher("../Main.jsp").forward(request, response);
		}else {
			request.setAttribute("mainRight", "Result.jsp?result="+"操作错误，请重新操作");
			request.getRequestDispatcher("../Main.jsp").forward(request, response);
		}
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
